package com.dlwx.parttimetalent.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.dlwx.parttimetalent.R;
import com.dlwx.parttimetalent.base.BaseActivity;
import com.dlwx.parttimetalent.utils.ToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SearchActivity extends BaseActivity {

    @BindView(R.id.title_left_one_btn)
    ImageView titleLeftOneBtn;
    @BindView(R.id.tv_middle_title)
    TextView tvMiddleTitle;
    @BindView(R.id.tv_confirm)
    TextView tvConfirm;
    @BindView(R.id.et_content)
    EditText etContent;
    private Handler mHandler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            inputshoworhind();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);
        ButterKnife.bind(this);
        initView();

    }

    private void initView() {
        tvMiddleTitle.setVisibility(View.VISIBLE);
        tvMiddleTitle.setText("搜索");
        titleLeftOneBtn.setVisibility(View.VISIBLE);
        mHandler.sendEmptyMessageDelayed(0,500);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @OnClick({R.id.title_left_one_btn, R.id.tv_confirm})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_left_one_btn:
                inputshoworhind();
                this.finish();
                break;
            case R.id.tv_confirm:
                String content=etContent.getText().toString();
                if(TextUtils.isEmpty(content)){
                    ToastUtils.toastForShort(SearchActivity.this,"搜索内容不能为空");
                    return;
                }
                Intent i=new Intent(SearchActivity.this, ClassifyListActivity.class);
                i.putExtra("search",content);
                startActivity(i);
                break;
        }
    }

    public void inputshoworhind(){

        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
//        if (getWindow().getAttributes().softInputMode == WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE) {
//        }
//        etContent.setFocusable(true);
//        etContent.setFocusableInTouchMode(true);
//        etContent.requestFocus();
//        InputMethodManager inputManager = (InputMethodManager)etContent.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
//        inputManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
